<?php

namespace App\Modules\Admin\Http\Controllers\Auth;

use App\Http\Controllers\BaseController;
use App\Modules\Admin\Services\AdminRoleService;
use Illuminate\Http\Request;

class AdminRoleController extends BaseController
{
    public function __construct(AdminRoleService $adminRoleService)
    {
        $this->middleware('check.adminLogin')->except('index');

        $this->adminRoleService = $adminRoleService;
    }

    public function index(Request $request)
    {
        $param = [];
        $data = $this->adminRoleService->getList($param);

        return $this->response->success($data);
    }

    public function show(Request $request)
    {
        $id = $request->input('id');
        $result = $this->adminRoleService->getInfo($id);

        return response()->json($result);
    }

    public function store(Request $request)
    {
        $param = $this->validationParameter([
            'name|角色名称' => 'require',
            'code|角色标识' => 'require',
            'description|描述' => 'noRequire',
        ]);

        $result = $this->adminRoleService->add($param);

        return response()->json($result);
    }

    public function update(Request $request)
    {
        $id = $request->input('id');
        $param = [];
        $result = $this->adminRoleService->update($param, $id);

        return response()->json($result);
    }

    public function destroy(Request $request)
    {
        $id = $request->input('id');
        $result = $this->adminRoleService->delete($id);

        return response()->json($result);
    }
}
